package com.ruoyi.web.controller.weather;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

@RestController
public class WeatherController {
    @GetMapping("/getWeatherByLocalIP")
    public AjaxResult getWeather() throws UnsupportedEncodingException{
        AjaxResult result = AjaxResult.success();
        String address = getLocationANDIp.getLocalCityName();
        // 调用天气Api
        String encodeCity = URLEncoder.encode(address, "UTF-8");
        String url = "http://apis.juhe.cn/simpleWeather/query?city="+encodeCity+"&key=0a224587d04bfae5bfc52ee54a1d4e3e";
        String weatherInfo = HttpUtils.sendGet(url);
        result.put("msg",weatherInfo);
        return result;

    }
}
